clear all
set maxvar 5000

*cd "1_Data/"
*ssc install ranktest
**********************************
*******PRE DELIMITATION AC********
**********************************
cd "/Users/tg2778/Dropbox/0_Reviews_RnRs/072022_JOP_Roads/v3_JOP/Replication - Roads"
log using "4_Log/9_IVResults.log"

use "1_Data/AC_pre-delim_dataset.dta", clear

egen acstateid = concat(VD01_AC_id stateid),p("_")

label var totalvillconn "Δ Connectivity"
label var percenteligiblevillage500 "Eligibility Instrument"

quietly: xi: ivreg2 change_incumbentvoteshare (totalvillconn = percenteligiblevillage500) i.statedistrict2, partial(i.statedistrict2) cluster(acstateid) first savefirst savefprefix(ac1)
quietly: estimates store aciv1, title(1)
quietly: estadd local fe "District"
quietly: estadd local cl "Constituency"

quietly: xi: ivreg2 change_incumbentvoteshare (totalvillconn = percenteligiblevillage500) i.statedistrict2, partial(i.statedistrict2) cluster(statedistrict2) first savefirst savefprefix(ac2)
quietly: estimates store aciv2, title(2)
quietly: estadd local fe "District"
quietly: estadd local cl "District"


**********************************
*******PRE DELIMITATION PC********
**********************************

use "1_Data/PC_pre-delim_dataset_select.dta", clear

egen pcstate = concat(PC_no_2001 stateid),p("_")

label var totalvillconn "Δ Connectivity"
label var percenteligiblevillage500 "Eligibility Instrument"

quietly: xi: ivreg2 change_incumbentvoteshare (totalvillconn = percenteligiblevillage500) i.state2, partial(i.state2) cluster(pcstate) first savefirst savefprefix(pc1)
quietly: estimates store pciv1, title(3)
quietly: estadd local fe "State"
quietly: estadd local cl "Constituency"

quietly: xi: ivreg2 change_incumbentvoteshare (totalvillconn = percenteligiblevillage500) i.state2, partial(i.state2) cluster(state2) first savefirst savefprefix(pc2)
quietly: estimates store pciv2, title(4)
quietly: estadd local fe "State"
quietly: estadd local cl "State"



****************************************************************************************

*cd "2_Tables"

esttab aciv* pciv* using "2_Tables/Manuscript_Table2_IV.doc", replace label cells(b(star fmt(3)) se(par fmt(3))) scalars("widstat F-stat" "N N" "fe Fixed Effects" "cl Cluster SE")sfmt("%9.2f" "%9.0f") nomtitles mgroups("State elections" "National elections", pattern(1 0 1 0)) title(IV Results: Roads provision does not increase ruling party(s) voteshare) rtf collabels(none) varlabels(totalvillconn "Δ Connectivity")

esttab ac1* ac2* pc1* pc2* using "2_Tables/Manuscript_Table2_IV.doc", append label cells(b(star fmt(3)) se(par fmt(3))) nomtitles nonumbers rtf collabels(none) noobs
log close
